<template>
  <div
      :style='{"width":"1200px","padding":"120px 7% 100px","margin":"0px auto","position":"relative","background":"url(http://codegen.caihongy.cn/20230109/138a4d606eae4a168810cef229969885.png) no-repeat center top,url(http://codegen.caihongy.cn/20230109/b95aeae1c1294f398aefb7c6cd5b16de.png) no-repeat center top,url(http://codegen.caihongy.cn/20230109/5ffc803e6682418eb7f0b09a98e35527.png) no-repeat center bottom,#99CC99"}'>
    <div class="section-title"
         :style='{"margin":"10px 0","color":"#333","textAlign":"center","background":"none","width":"100%","fontSize":"22px","lineHeight":"54px","fontWeight":"600"}'>
      论坛交流
    </div>
    <el-form :inline="true" :model="formSearch" class="list-form-pv">
      <div class="section-btn">
        <el-form-item>
          <el-input v-model="title" placeholder="标题"></el-input>
        </el-form-item>
        <el-button type="primary" @click="getForumList(1)"><i class="el-icon-search"></i>查询</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="toForumAdd">发布帖子</el-button>
      </div>
    </el-form>
    <div class="z-box">
      <div class="section-content" v-for="item in forumList" :key="item.id" @click="toForumDetail(item)">
        <div class="item-style">{{ item.title }}（发布人：{{ item.username }}）</div>
        <div class="item-style">{{ item.addtime }}</div>
      </div>
    </div>

    <el-pagination
        background
        class="pagination"
        :pager-count="7"
        :page-size="pageSize"
        :page-sizes="pageSizes"
        prev-text="<"
        next-text=">"
        :hide-on-single-page="true"
        :layout='["total","prev","pager","next","sizes","jumper"].join()'
        :total="total"
        :style='{"padding":"0","margin":"10px auto","whiteSpace":"nowrap","color":"#333","textAlign":"center","width":"100%","fontWeight":"500"}'
        @current-change="curChange"
        @prev-click="prevClick"
        @next-click="nextClick"
    ></el-pagination>

  </div>
</template>

<script>
export default {
  //数据集合
  data() {
    return {
      title: '',
      layouts: '',
      forumList: [],
      total: 1,
      pageSize: 10, pageSizes: [10, 20, 30, 50],
      totalPage: 1
    }
  },
  created() {
    this.getForumList(1);
  },
  //方法集合
  methods: {
    getForumList(page) {
      let params = {page, limit: this.pageSize, isdone: '开放', sort: 'addtime', order: 'desc'};
      let searchWhere = {};
      if (this.title != '') searchWhere.title = '%' + this.title + '%';
      this.$http.get('forum/flist', {params: Object.assign(params, searchWhere)}).then(res => {
        if (res.data.code == 0) {
          this.forumList = res.data.data.list;
          this.total = res.data.data.total;
          this.pageSize = res.data.data.pageSize;
          this.pageSizes = [this.pageSize, this.pageSize * 2, this.pageSize * 3, this.pageSize * 5];
          this.totalPage = res.data.data.totalPage;
        }
      });
    },
    curChange(page) {
      this.getForumList(page);
    },
    prevClick(page) {
      this.getForumList(page);
    },
    nextClick(page) {
      this.getForumList(page);
    },
    toForumAdd() {
      this.$router.push('/index/forumAdd');
    },
    toForumDetail(item) {
      this.$router.push({path: '/index/forumDetail', query: {id: item.id, detailObj: JSON.stringify(item)}});
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.section {
  width: 900px;
  margin: 0 auto;
}

.section-content {
  display: flex;
  justify-content: space-between;
  line-height: 60px;
  cursor: pointer;
  box-sizing: border-box;
  padding: 0 10px;
}

.section-content:hover {
  background-color: #E4E7ED;
  color: #fff;
}

.item-style {
  color: #909399;
  font-weight: 400;
}

.section-btn {
  text-align: right;
  margin-bottom: 15px;
  padding-right: 10px;
}

.z-box {
  width: 100% !important;
}

.el-pagination ::v-deep .el-pagination__total {
  margin: 0 10px 0 0;
  color: #666;
  font-weight: 400;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .btn-prev {
  border: none;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #666;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  min-width: 35px;
  height: 28px;
}

.el-pagination ::v-deep .btn-next {
  border: none;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #666;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  min-width: 35px;
  height: 28px;
}

.el-pagination ::v-deep .btn-prev:disabled {
  border: none;
  cursor: not-allowed;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #C0C4CC;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .btn-next:disabled {
  border: none;
  cursor: not-allowed;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #C0C4CC;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .el-pager {
  padding: 0;
  margin: 0;
  display: inline-block;
  vertical-align: top;
}

.el-pagination ::v-deep .el-pager .number {
  cursor: pointer;
  padding: 0 4px;
  margin: 0 5px;
  color: #666;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  border-radius: 2px;
  background: #f4f4f5;
  text-align: center;
  min-width: 30px;
  height: 28px;
}

.el-pagination ::v-deep .el-pager .number:hover {
  cursor: pointer;
  padding: 0 4px;
  margin: 0 5px;
  color: #ff9966;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  border-radius: 2px;
  background: #f4f4f5;
  text-align: center;
  min-width: 30px;
  height: 28px;
}

.el-pagination ::v-deep .el-pager .number.active {
  cursor: default;
  padding: 0 4px;
  margin: 0 5px;
  color: #FFF;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  border-radius: 2px;
  background: #ff9966;
  text-align: center;
  min-width: 30px;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__sizes {
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input {
  margin: 0 5px;
  width: 100px;
  position: relative;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input .el-input__inner {
  border: 1px solid #DCDFE6;
  cursor: pointer;
  padding: 0 25px 0 8px;
  color: #606266;
  display: inline-block;
  font-size: 13px;
  line-height: 28px;
  border-radius: 3px;
  outline: 0;
  background: #FFF;
  width: 100%;
  text-align: center;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input span.el-input__suffix {
  top: 0;
  position: absolute;
  right: 0;
  height: 100%;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input .el-input__suffix .el-select__caret {
  cursor: pointer;
  color: #C0C4CC;
  width: 25px;
  font-size: 14px;
  line-height: 28px;
  text-align: center;
}

.el-pagination ::v-deep .el-pagination__jump {
  margin: 0 0 0 24px;
  color: #606266;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__jump .el-input {
  border-radius: 3px;
  padding: 0 2px;
  margin: 0 2px;
  display: inline-block;
  width: 50px;
  font-size: 14px;
  line-height: 18px;
  position: relative;
  text-align: center;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__jump .el-input .el-input__inner {
  border: 1px solid #DCDFE6;
  cursor: pointer;
  padding: 0 3px;
  color: #606266;
  display: inline-block;
  font-size: 14px;
  line-height: 28px;
  border-radius: 3px;
  outline: 0;
  background: #FFF;
  width: 100%;
  text-align: center;
  	  	height: 28px;
  	  }
</style>
